import Vue from "vue";
import Router from "vue-router";
import Login from "@/components/Login.vue";
import Home from "@/components/Home.vue";
import Infogathermanage from "../views/infogathermanage.vue";
import Teachertraininfo from "../views/teachertraininfo.vue"
import Studentstatus from '../views/studentstatus.vue'
import Newborngathermessage from '../views/newborngathermessage.vue'
import Graduationjobinfo from '../views/graduationjobinfo.vue'
import HomeBig from '../views/homgBig.vue'
import "../plugins/element";

Vue.use(Router);

const router = new Router({
  routes: [
    {
      path: "/",
      name: "login",
      redirect: "/login"
    },
    {
      path: "/login",
      component: Login
    },
    {
      path: "/homeBig",
      component: HomeBig
    },

    {
      path: "/home",
      component: Home,
      children: [
        {
          path: "/infogathermanage",
          component: Infogathermanage
        },
        {
          path: "/teachertraininfo",
          component: Teachertraininfo
        },
        {
          path: "/studentstatus",
          component: Studentstatus
        },
        {
          path: "/newborngathermessage",
          component: Newborngathermessage
        },
        {
          path: "/graduationjobinfo",
          component: Graduationjobinfo
        }
      ]
    }
  ]
});

router.beforeEach((to, from, next) => {
  if (to.path === "/login") return next();
  // 获取token值
  const token = window.sessionStorage.getItem("token");
  if (token != null) return next();
  next("login");
});

export default router;
